/**
 * 
 */
package com.keggview.application.xml.datatypes;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamOmitField;


/**
 * @author Pablo
 * 
 * 
 * The component element is a subelement of the entry element, and is used when
 * the entry element is a complex node; namely, when the type attribute value of
 * the entry element is "group". The nodes that constitute the complex are
 * specified by recurrent calls. For example, when the complex is composed of
 * two nodes, two component elements are specified. The attribute of this
 * element is as follows.
 */
@XStreamAlias("component")
public class Component extends Base {

	/**
	 * The id attribute specifies the identification number of this component.
	 * The entry element of "group" type is specified by a complete set of
	 * component elements.
	 */
	@XStreamAsAttribute
	private Integer id;

	@XStreamOmitField
	private Entry component;

	
	private Component() {
		Registry.register(this);
	}

	/**
	 * @param id
	 */
	public Component(Integer id) {
		this();
		this.id = id;
		this.component = null;
	}

//	public Component(Element element) {
//		this();
//		this.id = Integer.valueOf(element.attribute("id").getValue());
//		this.component = null;
//	}

	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @return the component
	 */
	public Entry getComponent() {
		if (this.component == null) {
			this.component = Registry.hEntries.get(this.id);
		}
		return component;
	}

	/**
	 * @param component
	 *            the component to set
	 */
	public void setComponent(Entry component) {
		this.component = component;
		this.id = component.getId();
	}

}
